package com.example.exerciseextract2.movdel;

import android.util.Log;

import com.example.exerciseextract2.base.BaseModel;
import com.example.exerciseextract2.bean.RvBean;
import com.example.exerciseextract2.net.HttpUtil;
import com.example.exerciseextract2.net.ResultCallBack;
import com.example.exerciseextract2.net.RxUtils;

import java.util.ArrayList;

import io.reactivex.Flowable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.processors.ReplayProcessor;
import io.reactivex.schedulers.Schedulers;
import io.reactivex.subscribers.ResourceSubscriber;
import retrofit2.Retrofit;

/**
 * Created by 阿炜啊 on 2020/7/12.
 */

public class MainPageModel extends BaseModel {

    public void getData(final ResultCallBack<RvBean> callBack){

        HttpUtil.getInstance()
                .getWanService()
                .getDate()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .compose(RxUtils.<RvBean>rxSchedulerHelper())//切换观察者和被观察者的线程
                .subscribeWith(new ResourceSubscriber<RvBean>() {
                    @Override
                    public void onNext(RvBean rvBean) {

                        callBack.onSuccess(rvBean);
                    }

                    @Override
                    public void onError(Throwable t) {

                        callBack.onFail(t.getMessage());
                        Log.e("error",t.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });


    }

}
